﻿function formattedDate(vcontrol)
{
  if (document.getElementById(vcontrol).value != "")
  {
    var dateStr = document.getElementById(vcontrol).value;
    var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{2,4})$/;
    var matchArray = dateStr.match(datePat); // is the format ok?
    if (matchArray == null) return ;

    da = new Date(document.getElementById(vcontrol).value) // Create a Date Object set to the last modifed date 
    dy = da.getFullYear() ;
    dm = da.getMonth() + 1 ;
    dd = da.getDate(); 
    if ( dy < 1900 ) dy = dy + 100;  
    ys = new String(dy) // Convert year, month and date to strings 
    ms = new String(dm) ; 
    ds = new String(dd) ;  
    if ( ms.length == 1 ) ms = "0" + ms; // Add leading zeros to month and date if required 
    if ( ds.length == 1 ) ds = "0" + ds;   
    ys = ms + "/" + ds + "/" + ys// Combine year, month and date
    document.getElementById(vcontrol).value = ys;
   
 }
}